package org.example.Day3.Time;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Test2 {
    public static void main(String[] args ) throws ParseException {
        //掌握SimpleDateFormat使用
        Date d = new Date();
        System.out.println(d);

        long time = d.getTime();
        System.out.println(time);


        //格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss EEEa");
        String rs = sdf.format(d);
        String rs2 = sdf.format(time);
        System.out.println(rs);
        System.out.println(rs2);
        System.out.println("---------------");


        String dateStr = "2022-12-12 12:12:11";
        //简单格式化日期 指定时间格式必须与被破解格式一致
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" );
        Date d2 = sdf2.parse(dateStr);
        System.out.println(d2);
    }
}
